package com.oydsoft.auth.service;

import com.oydsoft.common.exception.CustomException;
import com.oydsoft.common.model.BaseApiService;
import com.oydsoft.common.model.BaseResponse;
import com.oydsoft.common.model.response.ResultCode;
import jdk.nashorn.internal.runtime.logging.Logger;
import org.springframework.core.annotation.Order;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;


@ControllerAdvice
@Order(2)
public class ExcepitionAdvice extends BaseApiService {

    @ExceptionHandler(value = CustomException.class)
    @ResponseBody
    public BaseResponse DuplicateKeyExceptionHandler(HttpServletRequest request, CustomException e) throws Exception {
        String message = e.getResultCode().message();
        /*ResultCode resultCode = e.getResultCode();
        int code = resultCode.code();
        if (code==23005){
            throw new RuntimeException("账号密码错误!");
        }*/
        return setResultError(message);
    }
}
